<!-- 市级 - 自建出租房屋隐患录入系统汇总表（居住） -->
<template>
  <div>
    <div class="header-yhtj-zx">
      <div class="title">
        <div>
          <!-- <a-space>
            <span>场所类型：</span>
            <a-select
              ref="select"
              v-model:value="type_cs"
              style="width: 120px"
              :options="optionsCS"
              @change="handleCsCheck"
            />
          </a-space>
          <a-space>
            <span>隐患类型：</span>
            <a-select
              ref="select"
              v-model:value="type_yh"
              style="width: 120px"
              :options="optionsYH"
              @change="handleYhCheck"
            />
              </a-space> -->
          <a-space>
            <span>专项类型：</span>
            <a-select
              ref="select"
              v-model:value="type_zx"
              style="width: 120px"
              :options="optionsZH"
              @change="handleZxCheck"
            />
          </a-space>
        </div>
        <div class="table-settings">
          <ImportSetting
            :tableData="tableData"
            :tableColumns="getImportExcel()"
            :wscolsList="wscolsList"
            ref="ImporBusinessDom"
            :excelName="getExcelName()"
            @click="importBusinessFn"
          />
        </div>
      </div>
      <div class="search">
        <div>
          <!-- <a-space>
            <span>开始时间：</span>
            <a-date-picker v-model:value="startDate" :format="dateFormat" />
          </a-space>
          <a-space>
            <span>结束时间：</span>
            <a-date-picker v-model:value="endDate" :format="dateFormat" />
          </a-space>
          <a-space>
            <a-button @click="changeTimeBefore315" style="margin-left: 10px">315前</a-button>
            <a-button @click="changeTimeAfter315">315后</a-button>
              </a-space> -->
          <a-space class="search-btn">
            <a-button type="primary" v-if="isShowBackBtn()" @click="goBack">返回</a-button>
            <a-button type="primary" @click="searchBtn">查询</a-button>
          </a-space>
        </div>
      </div>
    </div>
    <a-table
      :dataSource="tableData"
      :columns="currentColumns"
      :pagination="false"
      bordered
      :scroll="{ x: 1000, y: tableHeight }"
      :loading="loading"
    >
      <template #headerCell="{ column }">
        <!-- 存量 -- 房屋 -->
        <template v-if="column.key === 'fxhouse315'">
          <Tooltip placement="top">
            <template #title>
              <span>315之前有隐患的房屋总数</span>
            </template>
            <span style="cursor: pointer; font-weight: 550"> 有隐 </span>
          </Tooltip>
        </template>
        <template v-if="column.key === 'cl_scfw315'">
          <Tooltip placement="top">
            <template #title>
              <span>已消除(消除时间不限)发现时间315之前</span>
            </template>
            <span style="cursor: pointer; font-weight: 550"> 消除 </span>
          </Tooltip>
        </template>
        <template v-if="column.key === 'cl_syfw315'">
          <Tooltip placement="top">
            <template #title>
              <span>未消除，(发现时间315 之前) </span>
            </template>
            <span style="cursor: pointer; font-weight: 550"> 剩余 </span>
          </Tooltip>
        </template>
        <!-- 存量 -- 隐患 -->
        <template v-if="column.key === 'cl_fx315'">
          <Tooltip placement="top">
            <template #title>
              <span>315之前有隐患总数</span>
            </template>
            <span style="cursor: pointer; font-weight: 550"> 数量 </span>
          </Tooltip>
        </template>
        <template v-if="column.key === 'cl_xc315'">
          <Tooltip placement="top">
            <template #title>
              <span>已消除(消除时间不限),发现时间315之前</span>
            </template>
            <span style="cursor: pointer; font-weight: 550"> 消除 </span>
          </Tooltip>
        </template>
        <template v-if="column.key === 'cl_sy315'">
          <Tooltip placement="top">
            <template #title>
              <span>未消除(发现时间315之前)</span>
            </template>
            <span style="cursor: pointer; font-weight: 550"> 剩余 </span>
          </Tooltip>
        </template>
        <!-- 新增 -- 隐患 -->
        <template v-if="column.key === 'xz'">
          <Tooltip placement="top">
            <template #title>
              <span>315之后新增的隐患总数</span>
            </template>
            <span style="cursor: pointer; font-weight: 550"> 数量 </span>
          </Tooltip>
        </template>
        <template v-if="column.key === 'xc_all'">
          <Tooltip placement="top">
            <template #title>
              <span>针对315之后新增隐患的消除</span>
            </template>
            <span style="cursor: pointer; font-weight: 550"> 消除 </span>
          </Tooltip>
        </template>
        <template v-if="column.key === 'sy_all'">
          <Tooltip placement="top">
            <template #title>
              <span>针对315之后新增隐患的剩余</span>
            </template>
            <span style="cursor: pointer; font-weight: 550"> 剩余 </span>
          </Tooltip>
        </template>
        <!-- 现有 -- 隐患  xyyhfw sy_315-->
        <template v-if="column.key === 'xyyhfw'">
          <Tooltip placement="top">
            <template #title>
              <span>全部有隐患房屋总数</span>
            </template>
            <span style="cursor: pointer; font-weight: 550"> 房屋 </span>
          </Tooltip>
        </template>
        <template v-if="column.key === 'sy_315'">
          <Tooltip placement="top">
            <template #title>
              <span>全部剩余隐患总数</span>
            </template>
            <span style="cursor: pointer; font-weight: 550"> 隐患 </span>
          </Tooltip>
        </template>
      </template>
    </a-table>
    <Detail
      v-model:visible="visible"
      title="抽屉标题"
      :width="1000"
      :detailTableHeight="detailTableHeight"
      :closable="true"
      :destroyOnClose="true"
      :data="detailData"
      :detailParams="detailParams"
      :currentXzqdmname="currentXzqdmname"
      :currentTitle="currentTitle"
      @close="handleClose"
    >
      <!-- <p>抽屉内容</p> --> </Detail
    >
  </div>
</template>
<script lang="ts" setup>
  // import moment, { Moment } from 'moment';
  import moment from 'moment';
  import dayjs from 'dayjs';
  import { ref, reactive, toRefs, onMounted, onBeforeMount, computed, nextTick } from 'vue';
  import { Tooltip, message } from 'ant-design-vue';
  import ImportSetting from '../housesDangerBusiness/ImportSetting.vue';
  import Detail from './component/detailDrawer.vue';
  import { getFireDangerAllList } from '/@/api/demo/system';
  import { iTableData, iTableColumns } from './types/table';
  import { iParams } from './types/params';

  import { useUserStore } from '/@/store/modules/user';

  // import { t } from '/@/hooks/web/useI18n';
  // 转义地区编码
  // import { selectClassFlyDict } from '/@/dict/bj_dict';
  const visible = ref(false);
  let detailData = ref<any[]>([]);
  let detailParams = ref({}); // 详情参数
  let detailTableHeight = ref<number>(0); // 表格高度
  let tableHeight = ref<number>(0); // 表格高度
  const dateFormat = 'YYYY-MM-DD';
  const startDate = ref<any>(null); // 开始时间
  const endDate = ref<any>(null); // 结束时间
  // 场所类型
  const optionsCS = ref<any[]>([
    {
      value: '3',
      label: '全部',
    },
    {
      value: '0',
      label: '居住',
    },
    {
      value: '1',
      label: '商业',
    },
  ]);
  // 隐患类型
  const optionsYH = ref<any[]>([
    {
      value: '0',
      label: '发现隐患',
    },
    {
      value: '1',
      label: '消隐',
    },
    {
      value: '2',
      label: '剩余',
    },
  ]);
  // 专项类型
  const optionsZH = ref<any[]>([
    {
      value: '0',
      label: '全部',
    },
    {
      value: '777',
      label: '777村',
    },
    {
      value: '108',
      label: '108村',
    },
  ]);
  let userInfo = ref<any>(null);
  let currentColumns = ref<any>([]);
  let data = reactive<{
    tableData: iTableData[];
    tableColumns: iTableColumns[];
    wscolsList: { wch: number }[];
    id: number | any;
    loading: Boolean;
    keyWorld: String;
    cityToken: string | any;
    startTime: string; // 开始时间
    endTime: string; // 结束时间
    type_cs: string; // 场所类型
    type_yh: string; // 隐患类型
    type_zx: string; // 专项类型
    jdCode: string; // 街道code
    qxCode: string; // 区县
    groupbyLever: string; // 0区县,1街镇,2村级
    groupbyLever_code: string; // 当前行等级编码
    currentXzqdmname: string; // 当前行政区名称
    currentTitle: string;
  }>({
    // 表格数据
    tableData: [],
    tableColumns: [
      {
        title: '序号',
        dataIndex: 'index',
        key: 'index',
        align: 'center',
        width: 70,
        fixed: 'left',
      },
      {
        title: '区县名称',
        dataIndex: 'xzqdmname',
        key: 'xzqdmname',
        align: 'center',
        // width: 100,
        customCell: (row, index, column) => {
          // console.log('@index ', index);
          // console.log('@row ', row);
          // console.log('@column ', column);
          let isNoHzyh =
            row.townname !== '汇总' || row.villagename !== '汇总' || row.xzqdmname !== '汇总'
              ? true
              : false;
          let style = 'cursor:pointer;text-decoration: underline; color: blue;';
          return {
            children: row.xzqdmname,
            style: `${isNoHzyh === true ? style : ''}`,
            class: 'cell-hover',
            onClick: () => {
              if (isNoHzyh) {
                data.groupbyLever = '1';
                data.qxCode = row.xzqdm; // 保存 东城区
                data.groupbyLever_code = row.xzqdm;
                data.loading = true;
                getData();
              }
            },
          };
        },
      },
      {
        title: '街镇 名称',
        dataIndex: 'townname',
        key: 'townname',
        align: 'center',
        // width: 130,
        customCell: (row, index, column) => {
          // console.log('@index ', index);
          // console.log('@row ', row);
          // console.log('@column ', column);
          let isNoHzyh =
            row.townname !== '汇总' || row.villagename !== '汇总' || row.xzqdmname !== '汇总'
              ? true
              : false;
          let style = 'cursor:pointer;text-decoration: underline; color: blue;';
          return {
            children: row.xzqdmname,
            style: `${isNoHzyh === true ? style : ''}`,
            class: 'cell-hover',
            onClick: () => {
              if (isNoHzyh) {
                data.groupbyLever = '2';
                data.jdCode = row.town;
                data.groupbyLever_code = row.town;
                data.loading = true;
                getData();
              }
            },
          };
        },
      },
      {
        title: '村庄 名称',
        dataIndex: 'villagename',
        key: 'villagename',
        align: 'center',
        // width: 130,
      },
      {
        title: '存量',
        children: [
          // 房屋
          {
            title: '房屋',
            children: [
              {
                title: '有隐',
                dataIndex: 'fxhouse315',
                key: 'fxhouse315',
                align: 'center',
                width: 80,
                customCell: (row, index, column) => {
                  let isNoHzyh =
                    row.townname !== '汇总' ||
                    row.villagename !== '汇总' ||
                    row.xzqdmname !== '汇总'
                      ? true
                      : false;
                  let style = 'cursor:pointer;text-decoration: underline; color: blue;';
                  let isNoZero = row[column.key] !== 0 ? true : false;
                  return {
                    children: row.xzqdmname,
                    style: `${isNoHzyh === true && isNoZero ? style : ''}`,
                    class: 'cell-hover',
                    onClick: async () => {
                      getDetailData(row, index, column, isNoHzyh, isNoZero);
                    },
                  };
                },
              },
              {
                title: '消除',
                dataIndex: 'cl_scfw315',
                key: 'cl_scfw315',
                align: 'center',
                width: 80,
                customCell: (row, index, column) => {
                  let isNoHzyh =
                    row.townname !== '汇总' ||
                    row.villagename !== '汇总' ||
                    row.xzqdmname !== '汇总'
                      ? true
                      : false;
                  let style = 'cursor:pointer;text-decoration: underline; color: blue;';
                  let isNoZero = row[column.key] !== 0 ? true : false;
                  return {
                    children: row.xzqdmname,
                    style: `${isNoHzyh === true && isNoZero ? style : ''}`,
                    class: 'cell-hover',
                    onClick: async () => {
                      getDetailData(row, index, column, isNoHzyh, isNoZero);
                    },
                  };
                },
              },
              {
                title: '剩余',
                dataIndex: 'cl_syfw315',
                key: 'cl_syfw315',
                align: 'center',
                width: 80,
                customCell: (row, index, column) => {
                  let isNoHzyh =
                    row.townname !== '汇总' ||
                    row.villagename !== '汇总' ||
                    row.xzqdmname !== '汇总'
                      ? true
                      : false;
                  let style = 'cursor:pointer;text-decoration: underline; color: blue;';
                  let isNoZero = row[column.key] !== 0 ? true : false;
                  return {
                    children: row.xzqdmname,
                    style: `${isNoHzyh === true && isNoZero ? style : ''}`,
                    class: 'cell-hover',
                    onClick: async () => {
                      getDetailData(row, index, column, isNoHzyh, isNoZero);
                    },
                  };
                },
              },
            ],
          },
          // 隐患
          {
            title: '隐患',
            children: [
              {
                title: '数量',
                dataIndex: 'cl_fx315',
                key: 'cl_fx315',
                align: 'center',
                width: 80,
                customCell: (row, index, column) => {
                  let isNoHzyh =
                    row.townname !== '汇总' ||
                    row.villagename !== '汇总' ||
                    row.xzqdmname !== '汇总'
                      ? true
                      : false;
                  let style = 'cursor:pointer;text-decoration: underline; color: blue;';
                  let isNoZero = row[column.key] !== 0 ? true : false;
                  return {
                    children: row.xzqdmname,
                    style: `${isNoHzyh === true && isNoZero ? style : ''}`,
                    class: 'cell-hover',
                    onClick: async () => {
                      getDetailData(row, index, column, isNoHzyh, isNoZero);
                    },
                  };
                },
              },
              {
                title: '消除',
                dataIndex: 'cl_xc315',
                key: 'cl_xc315',
                align: 'center',
                width: 80,
                customCell: (row, index, column) => {
                  let isNoHzyh =
                    row.townname !== '汇总' ||
                    row.villagename !== '汇总' ||
                    row.xzqdmname !== '汇总'
                      ? true
                      : false;
                  let style = 'cursor:pointer;text-decoration: underline; color: blue;';
                  let isNoZero = row[column.key] !== 0 ? true : false;
                  return {
                    children: row.xzqdmname,
                    style: `${isNoHzyh === true && isNoZero ? style : ''}`,
                    class: 'cell-hover',
                    onClick: async () => {
                      getDetailData(row, index, column, isNoHzyh, isNoZero);
                    },
                  };
                },
              },
              // 居住 商业
              {
                title: '剩余',
                dataIndex: 'cl_sy315',
                key: 'cl_sy315',
                align: 'center',
                width: 80,
                customCell: (row, index, column) => {
                  let isNoHzyh =
                    row.townname !== '汇总' ||
                    row.villagename !== '汇总' ||
                    row.xzqdmname !== '汇总'
                      ? true
                      : false;
                  let style = 'cursor:pointer;text-decoration: underline; color: blue;';
                  let isNoZero = row[column.key] !== 0 ? true : false;
                  return {
                    children: row.xzqdmname,
                    style: `${isNoHzyh === true && isNoZero ? style : ''}`,
                    class: 'cell-hover',
                    onClick: async () => {
                      getDetailData(row, index, column, isNoHzyh, isNoZero);
                    },
                  };
                },
              },
            ],
          },
        ],
      },

      {
        title: '新增',
        children: [
          {
            title: '隐患',
            children: [
              {
                title: '数量',
                dataIndex: 'xz',
                key: 'xz',
                align: 'center',
                width: 130,
                customCell: (row, index, column) => {
                  let isNoHzyh =
                    row.townname !== '汇总' ||
                    row.villagename !== '汇总' ||
                    row.xzqdmname !== '汇总'
                      ? true
                      : false;
                  let style = 'cursor:pointer;text-decoration: underline; color: blue;';
                  let isNoZero = row[column.key] !== 0 ? true : false;
                  return {
                    children: row.xzqdmname,
                    style: `${isNoHzyh === true && isNoZero ? style : ''}`,
                    class: 'cell-hover',
                    onClick: async () => {
                      getDetailData(row, index, column, isNoHzyh, isNoZero);
                    },
                  };
                },
              },

              {
                title: '消除',
                dataIndex: 'xc_all',
                key: 'xc_all',
                align: 'center',
                width: 130,
                customCell: (row, index, column) => {
                  let isNoHzyh =
                    row.townname !== '汇总' ||
                    row.villagename !== '汇总' ||
                    row.xzqdmname !== '汇总'
                      ? true
                      : false;
                  let style = 'cursor:pointer;text-decoration: underline; color: blue;';
                  let isNoZero = row[column.key] !== 0 ? true : false;
                  return {
                    children: row.xzqdmname,
                    style: `${isNoHzyh === true && isNoZero ? style : ''}`,
                    class: 'cell-hover',
                    onClick: async () => {
                      getDetailData(row, index, column, isNoHzyh, isNoZero);
                    },
                  };
                },
              },
              {
                title: '剩余',
                dataIndex: 'sy_all',
                key: 'sy_all',
                align: 'center',
                width: 130,
                customCell: (row, index, column) => {
                  let isNoHzyh =
                    row.townname !== '汇总' ||
                    row.villagename !== '汇总' ||
                    row.xzqdmname !== '汇总'
                      ? true
                      : false;
                  let style = 'cursor:pointer;text-decoration: underline; color: blue;';
                  let isNoZero = row[column.key] !== 0 ? true : false;
                  return {
                    children: row.xzqdmname,
                    style: `${isNoHzyh === true && isNoZero ? style : ''}`,
                    class: 'cell-hover',
                    onClick: async () => {
                      getDetailData(row, index, column, isNoHzyh, isNoZero);
                    },
                  };
                },
              },
            ],
          },
        ],
      },
      {
        title: '现有',
        children: [
          {
            title: '隐患',
            children: [
              {
                title: '房屋',
                dataIndex: 'xyyhfw',
                key: 'xyyhfw',
                align: 'center',
                width: 80,
                customCell: (row, index, column) => {
                  let isNoHzyh =
                    row.townname !== '汇总' ||
                    row.villagename !== '汇总' ||
                    row.xzqdmname !== '汇总'
                      ? true
                      : false;
                  let style = 'cursor:pointer;text-decoration: underline; color: blue;';
                  let isNoZero = row[column.key] !== 0 ? true : false;
                  return {
                    children: row.xzqdmname,
                    style: `${isNoHzyh === true && isNoZero ? style : ''}`,
                    class: 'cell-hover',
                    onClick: async () => {
                      getDetailData(row, index, column, isNoHzyh, isNoZero);
                    },
                  };
                },
              },
              {
                title: '隐患',
                dataIndex: 'sy_315',
                key: 'sy_315',
                align: 'center',
                width: 80,
                customCell: (row, index, column) => {
                  let isNoHzyh =
                    row.townname !== '汇总' ||
                    row.villagename !== '汇总' ||
                    row.xzqdmname !== '汇总'
                      ? true
                      : false;
                  let style = 'cursor:pointer;text-decoration: underline; color: blue;';
                  let isNoZero = row[column.key] !== 0 ? true : false;
                  return {
                    children: row.xzqdmname,
                    style: `${isNoHzyh === true && isNoZero ? style : ''}`,
                    class: 'cell-hover',
                    onClick: async () => {
                      getDetailData(row, index, column, isNoHzyh, isNoZero);
                    },
                  };
                },
              },
            ],
          },
        ],
      },
      // {
      //   title: '合计',
      //   dataIndex: 'sumall',
      //   key: 'sumall',
      //   align: 'center',
      //   width: 100,
      // },
    ],
    id: null,
    loading: false,
    keyWorld: '',
    startTime: '2023-03-16 00:00:00', // 开始时间
    endTime: '2043-03-16 00:00:00', // 结束时间
    type_cs: '3', // 场所类型 居住0商业1  全部 3
    type_yh: '0', // 隐患类型  0发现隐患 1消隐 2剩余
    type_zx: '777', // 专项类型 108,777,0(全部)
    groupbyLever: '0', // 0区县,1街镇,2村级
    groupbyLever_code: '',
    currentXzqdmname: '', // 当前行政区名称
    currentTitle: '', // 当前详情标题
    jdCode: '', // 街道code
    qxCode: '', // 区县code
    cityToken: '', // 判断是不是市区 110000 是北京市 展示搜索宽
    wscolsList: [{ wch: 15 }, { wch: 15 }, { wch: 15 }, { wch: 15 }, { wch: 15 }, { wch: 15 }],
  });
  // 表格的 ref Dom名称
  const ImporBusinessDom: any = ref(null);
  let {
    tableData,
    tableColumns,
    loading,
    wscolsList,
    type_cs,
    type_yh,
    type_zx,
    groupbyLever,
    currentXzqdmname,
    currentTitle,
  } = toRefs(data);
  function handleCsCheck(value: string) {
    data.type_cs = value;
    console.log('场所回调', data.type_cs);
  }
  function handleYhCheck(value: string) {
    data.type_yh = value;
    console.log('专项回调', data.type_yh);
  }
  function handleZxCheck(value: string) {
    data.type_zx = value;
    console.log('场所回调', data.type_zx);
  }
  // 时间组件的点击回调
  // function handleClick() {
  //   if (dateRange.value) {
  //     const [startDate, endDate] = dateRange.value;
  //     data.startTime = moment(startDate.$d).format('YYYY-MM-DD HH:mm:ss');
  //     data.endTime = moment(endDate.$d).format('YYYY-MM-DD HH:mm:ss');
  //     console.log('选中的起始日期：', data.startTime);
  //     console.log('选中的结束日期：', data.endTime);
  //   }
  // }
  // 改变时间后的回调
  // function changeTime() {
  //   const start: any = dayjs('2023-04-21 19:30:00');
  //   const end: any = dayjs('2023-04-28 19:30:00');
  //   dateRange.value = [start, end];
  //   handleClick();
  // }

  // 给时间组件重新赋值
  // 315 前
  function changeTimeBefore315() {
    const start: any = dayjs('2022-01-01');
    const end: any = dayjs('2023-03-15');
    startDate.value = start;
    endDate.value = end;
    getTime();
  }
  // 315后
  function changeTimeAfter315() {
    let time1: any = new Date().getTime();
    var date = new Date(time1);
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
    var strDate = Y + M + D;
    const start: any = dayjs('2023-03-16');
    const end: any = dayjs(`${strDate}`);
    startDate.value = start;
    endDate.value = end;
    getTime();
  }
  function getTime() {
    data.startTime = moment(startDate.value.$d).format('YYYY-MM-DD');
    data.endTime = moment(endDate.value.$d).format('YYYY-MM-DD');
    // console.log('@查询参数 -- 开始时间', data.startTime);
    // console.log('@查询参数 -- 结束时间', data.endTime);
  }
  function searchBtn() {
    // getExcelName();
    // console.log('@tableColumns', tableColumns.value);
    getTime();
    data.loading = true;
    getData();
  }
  // 打开抽屉
  function showDrawer() {
    visible.value = !visible.value;
  }
  function handleClose() {
    visible.value = !visible.value;
  }

  function goBack() {
    // console.log('返回', data.groupbyLever);
    const { role, district } = userInfo.value;
    data.loading = true;
    if (data.groupbyLever === '1') {
      data.groupbyLever = '0';
      data.groupbyLever_code = '';
      getData();
    } else if (data.groupbyLever === '2') {
      data.groupbyLever = '1';
      if (role === 'City') {
        data.groupbyLever_code = data.qxCode;
      } else if (role === 'Area') {
        data.groupbyLever_code = district.regionCode;
      }
      //  else if (role === 'Street') {
      //   data.groupbyLever_code = district.regionCode;
      // }
      getData();
    }
  }
  function isShowBackBtn() {
    const { role, district } = userInfo.value;
    // groupbyLever !== '0'
    let isShow = false;
    if (role === 'City') {
      if (data.groupbyLever !== '0') {
        isShow = true;
      }
    } else if (role === 'Area') {
      if (data.groupbyLever !== '0' && data.groupbyLever !== '1') {
        isShow = true;
      }
    } else if (role === 'Street') {
      isShow = false;
    }
    return isShow;
  }
  function getExcelName() {
    /*******************************************/
    let zxName = '全部村';
    if (data.type_zx === '108') {
      zxName = '108村';
    } else if (data.type_zx === '777') {
      zxName = '777村';
    } else if (data.type_zx === '0') {
      zxName = '全部村';
    }
    let csName = '全部场所';
    if (data.type_cs === '0') {
      csName = '居住';
    } else if (data.type_cs === '1') {
      csName = '商业';
    } else if (data.type_cs === '3') {
      csName = '全部场所';
    }
    let yhName = '发现隐患';
    if (data.type_yh === '0') {
      yhName = '发现隐患';
    } else if (data.type_yh === '1') {
      yhName = '消隐';
    } else if (data.type_yh === '3') {
      yhName = '剩余';
    }
    let time1: any = new Date().getTime();
    var date = new Date(time1);
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';

    // var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    // var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    // var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
    // var strDate = Y + M + D + h + m + s;
    var strDate = Y + M + D;
    // let Date = Date.new();
    // return `${zxName}_ ${csName}_${yhName}_${strDate}`;
    return `${zxName}_${strDate}`;
    // console.log('场所名称', csName);
    // // console.log('场所类型', data.type_yh);
    // console.log('专项名称', zxName);
    // console.log('隐患名称', yhName);
  }
  // 获取详情的数据
  const getDetailData = async (
    row: any,
    index: number,
    column: any,
    isNoHzyh: boolean,
    isNoZero: boolean,
  ) => {
    if (isNoHzyh && isNoZero) {
      let params: iParams = {
        // type_cs: data.type_cs,
        // type_yh: data.type_yh,
        // startTime: data.startTime + ' 00:00:00',
        // endTime: data.endTime + ' 23:59:59',
        type_zx: data.type_zx,
        groupbyLever: data.groupbyLever,
        groupbyLever_code: row.xzqdm,
        groupbyLever_code_project: column.key,
      };

      detailParams.value = params;
      data.currentTitle = column.__originColumn__.title;
      showDrawer();
    }
  };
  function setInitParams() {
    const { role, district } = userInfo.value;
    if (role === 'City') {
      data.groupbyLever = '0';
      data.groupbyLever_code = ''; //
    } else if (role === 'Area') {
      data.groupbyLever = '1';
      data.groupbyLever_code = district.regionCode; // 当前区县
    } else if (role === 'Street') {
      data.groupbyLever = '2';
      data.groupbyLever_code = district.regionCode; // 当前街道
    }
  }
  async function getData() {
    // const { role } = userInfo.value;
    // console.log('@useUserStore==用户信息--role', role);
    // 北京市 的数据
    getCurrentColumns();
    let params: iParams = {
      type_zx: data.type_zx,
      type_cs: data.type_cs,
      type_yh: data.type_yh,
      groupbyLever: data.groupbyLever,
      groupbyLever_code: data.groupbyLever_code,
      startTime: data.startTime + ' 00:00:00',
      endTime: data.endTime + ' 23:59:59',
    };
    // console.log('@市级参数', params);
    // getBusinessList,
    // getLivingList,
    loading.value = true;
    // let res: any = await getLivingList(params);
    let res: any = await getFireDangerAllList(params);
    console.log('@res', res);
    console.log('@res--(居住)系统汇总表', res);
    if (res || res.length > 0) {
      loading.value = false;
      res.forEach((item: any, index: number) => {
        // item.name = selectClassFlyDict(item.xzqdm);
        item.index = index + 1;
        // console.log('@bicycle', item.use_electric_bicycle);
      });
      // 算列和
      let fxhouse315_count = total(res, 'fxhouse315');
      let cl_fx315_count = total(res, 'cl_fx315');
      let xyyhfw_count = total(res, 'xyyhfw');
      let cl_syfw315_count = total(res, 'cl_syfw315');
      let cl_scfw315_count = total(res, 'cl_scfw315');

      let index_count = res.length + 1;
      let cl_xc315_count = total(res, 'cl_xc315');
      let cl_sy315_count = total(res, 'cl_sy315');
      let xchouse_all_count = total(res, 'xchouse_all');
      let xchouse_315_count = total(res, 'xchouse_315');
      let xz_count = total(res, 'xz');
      let xc_all_count = total(res, 'xc_all');
      let xc_315_count = total(res, 'xc_315');
      let sy_all_count = total(res, 'sy_all');
      let sy_315_count = total(res, 'sy_315');
      let allObj = {
        fxhouse315: fxhouse315_count,
        cl_fx315: cl_fx315_count,
        xyyhfw: xyyhfw_count,
        cl_syfw315: cl_syfw315_count,
        cl_scfw315: cl_scfw315_count,
        index: index_count,
        cl_xc315: cl_xc315_count,
        cl_sy315: cl_sy315_count,
        xzqdmname: '汇总',
        townname: '汇总',
        villagename: '汇总',
        xchouse_all: xchouse_all_count,
        xchouse_315: xchouse_315_count,
        xz: xz_count,
        xc_all: xc_all_count,
        xc_315: xc_315_count,
        sy_all: sy_all_count,
        sy_315: sy_315_count,
      };
      // console.log('data', data);
      data.tableData = [...res, allObj];
    }
  }

  // 计算总数的方法
  function total(arr: any, item: any) {
    let total = arr.reduce((pre: any, cur: any) => {
      return pre + cur[item];
    }, 0);
    return total;
  }
  function importBusinessFn() {
    if (ImporBusinessDom.value) {
      ImporBusinessDom.value.importFn();
    }
  }
  function getUserInfo() {
    const userStore = useUserStore();
    userInfo.value = userStore?.getUserInfo;
  }
  // 获取当前列
  function getCurrentColumns() {
    const { role, district } = userInfo.value;
    console.log('@district', district);
    // data.groupbyLever_code = district.id;
    // let arr: any[] = [];
    if (role === 'City') {
      // qx
      currentColumns.value = data.tableColumns.filter(
        (item) => item.key !== 'townname' && item.key !== 'villagename',
      );
      if (data.groupbyLever === '0') {
        // 0区县
        currentColumns.value = data.tableColumns.filter(
          (item) => item.key !== 'townname' && item.key !== 'villagename',
        );
      } else if (data.groupbyLever === '1') {
        // 1街镇
        currentColumns.value = data.tableColumns.filter(
          (item) => item.key !== 'villagename' && item.key !== 'xzqdmname',
        );
      } else if (data.groupbyLever === '2') {
        // 2村级
        currentColumns.value = data.tableColumns.filter(
          (item) => item.key !== 'townname' && item.key !== 'xzqdmname',
        );
      }
    } else if (role === 'Area') {
      // jz
      currentColumns.value = data.tableColumns.filter(
        (item) => item.key !== 'villagename' && item.key !== 'xzqdmname',
      );
      if (data.groupbyLever === '1') {
        // 1街镇
        currentColumns.value = data.tableColumns.filter(
          (item) => item.key !== 'villagename' && item.key !== 'xzqdmname',
        );
      } else if (data.groupbyLever === '2') {
        // 2村级
        currentColumns.value = data.tableColumns.filter(
          (item) => item.key !== 'townname' && item.key !== 'xzqdmname',
        );
      }
    } else if (role === 'Street') {
      // 街道账号
      currentColumns.value = data.tableColumns.filter(
        (item) => item.key !== 'townname' && item.key !== 'xzqdmname',
      );
    }
  }
  // function getImportExcel() {
  //   let arr: any = [];
  //   data.tableColumns.filter((item: any) => {
  //     if (item.title === '315前' || item.title === '315后') {
  //       arr.push(...item.children);
  //     } else {
  //       arr.push(item);
  //     }
  //   });
  //   if (data.groupbyLever === '0') {
  //     // 0区县
  //     let a = arr.filter((item) => item.key !== 'townname' && item.key !== 'villagename');
  //     // console.log('A', a);
  //     return a;
  //   } else if (data.groupbyLever === '1') {
  //     // 1街镇
  //     let a = arr.filter((item) => item.key !== 'villagename' && item.key !== 'xzqdmname');
  //     return a;
  //   } else if (data.groupbyLever === '2') {
  //     // 2村级
  //     let a = arr.filter((item) => item.key !== 'townname' && item.key !== 'xzqdmname');
  //     return a;
  //   }
  // }
  function flatten(arr: any) {
    let result: any = [];
    for (let i = 0; i < arr.length; i++) {
      let item = arr[i];
      result.push(item);
      if (item.children) {
        result = result.concat(flatten(item.children));
        delete item.children;
      }
    }
    return result;
  }

  function getImportExcel() {
    let arr = JSON.parse(JSON.stringify(data.tableColumns));
    let a = flatten(arr);
    let newArr: any = [];
    a.map((item: any) => {
      if (item.title && item.dataIndex) {
        newArr.push(item);
      }
    });
    // console.log('@q2', newArr);
    const filters = {
      '0': (item: any) => item.key !== 'townname' && item.key !== 'villagename',
      '1': (item: any) => item.key !== 'villagename' && item.key !== 'xzqdmname',
      '2': (item: any) => item.key !== 'townname' && item.key !== 'xzqdmname',
    };

    return newArr.filter(filters[data.groupbyLever]);

    // const arr: any = [];
    // data.tableColumns.forEach((item: any) => {
    //   if (item.title === '315前' || item.title === '315后') {
    //     arr.push(...item.children);
    //   } else {
    //     arr.push(item);
    //   }
    // });
    // const filters = {
    //   '0': (item: any) => item.key !== 'townname' && item.key !== 'villagename',
    //   '1': (item: any) => item.key !== 'villagename' && item.key !== 'xzqdmname',
    //   '2': (item: any) => item.key !== 'townname' && item.key !== 'xzqdmname',
    // };
    // return arr.filter(filters[data.groupbyLever]);
  }
  const getTableHeight = () => {
    setTimeout(() => {
      detailTableHeight.value = window.innerHeight - 182;
      tableHeight.value = window.innerHeight - 292;
      // console.log(`表格高度`, tableHeight.value);
    });
  };
  onBeforeMount(() => {
    getUserInfo();
  });
  onMounted(() => {
    getImportExcel();
    changeTimeAfter315();
    setInitParams();
    getData();
    getTableHeight();
  });
</script>

<style lang="less">
  .header-yhtj-zx {
    width: 100%;
    // height: 250px;
    display: flex;
    // border: 1px solid red;
    line-height: 40px;
    justify-content: space-between;
    flex-direction: column;

    .title {
      display: flex;
      justify-content: space-between;
    }

    .search {
      // border: 1px solid green;
      height: 40px;
      position: relative;

      .search-btn {
        position: absolute;
        right: 0;
        top: 2px;
        margin-right: 12px;
      }
    }

    .table-settings {
      & > * {
        margin-right: 12px;
      }

      svg {
        width: 2em;
        height: 2em;
      }
    }
  }

  .cell-hover:hover {
    background-color: #df0909;
  }
</style>
